<?php

namespace App\Exceptions;


use Exception;
use Illuminate\Http\Request;

class InvalidRequestException extends Exception
{
    public function __construct($message = "", $code = 400)
    {
        parent::__construct($message, $code);
    }

    public function render(Request $request)
    {
        if($request->expectsJson()){
            //json()方法第二个参数就是http返回码
            return response()->json(['msg'=>$this->message,$this->code]);
        }

        return view('pages.error',['msg'=>$this->message]);
    }
}
